package com.zwk.edu.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zwk.base.entity.CommonResult;
import com.zwk.edu.entity.Course;
import com.zwk.edu.entity.Teacher;
import com.zwk.edu.service.CourseService;
import com.zwk.edu.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author zwk
 * @create 2022/8/30 10:57
 */
@RestController
@CrossOrigin
@RequestMapping("/edu/teacherfront")
public class TeacherFrontController {

    @Autowired
    private TeacherService teacherService;

    @Autowired
    private CourseService courseService;

    // 分页获取讲师列表
    @GetMapping("/getTeacherList/{current}/{limit}")
    public CommonResult getTeacherList(@PathVariable("current") Integer current,
                                       @PathVariable("limit") Integer limit){
        Page<Teacher> page = new Page<>(current, limit);
        Map<String, Object> map = teacherService.getTeacherPageList(page);
        return CommonResult.ok().data(map);
    }

    // 根据id获取讲师信息以及所讲课程
    @GetMapping("/getTeacherFrontInfo/{id}")
    public CommonResult getTeacherFrontInfo(@PathVariable("id") String id){
        // 获取讲师信息
        Teacher teacher = teacherService.getById(id);
        // 获取讲师所讲课程
        QueryWrapper<Course> wrapper = new QueryWrapper<>();
        wrapper.eq("teacher_id", id);
        wrapper.eq("status", "Normal");
        List<Course> courseList = courseService.list(wrapper);
        return CommonResult.ok().data("teacher", teacher).data("courseList", courseList);
    }


}
